Fundamentos de la Ingeniería de Prompts
Ingeniería de Prompts (IP) es el proceso de diseñar y optimizar entradas de texto para guiar a los Modelos de Lenguaje Grandes (MLG) hacia resultados de alta calidad y coherentes.
1. Definición de la Interfaz
¿Qué: Sirve como la interfaz principal de "programación" para la inteligencia artificial generativa.
¿Por qué: Transforma la interacción desde una predicción textual cruda e impredecible hasta la ejecución intencional y estructurada de instrucciones.
2. Fundamentos de los Modelos
- MLGs Base: Entrenados simplemente para predecir el siguiente token basándose en relaciones estadísticas en grandes conjuntos de datos, maximizando la probabilidad $P(w_t | w_1, w_2, ..., w_{t-1})$.
- MLGs Ajustados por Instrucciones: Afinados mediante Aprendizaje por Refuerzo con Retroalimentación Humana (RLHF) para seguir explícitamente direcciones específicas y actuar como asistentes útiles.
3. Anatomía de un Prompt Exitoso
¿Cómo: Un prompt sólido generalmente contiene:
- Instrucción: La acción específica requerida.
- Contenido Primario: Los datos objetivo a procesar.
- Contenido Secundario: Parámetros, formato o restricciones (para abordar la estocasticidad y las alucinaciones).
La Realidad de la Tokenización
Los modelos no leen palabras; procesan tokens—unidades más pequeñas de secuencias de texto utilizadas para calcular probabilidades estadísticas.
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
What is the primary difference between a Base LLM and an Instruction-Tuned LLM?
Question 2
Why is the use of delimiters (like triple backticks or hashes) considered a best practice in prompt engineering?
Challenge: Tutor AI Constraints
Refining prompts for educational safety.
You are building a tutor-style AI for a startup. The model is currently giving away answers too quickly and sometimes making up facts when it doesn't know the answer.
Task 1
Implement "Chain-of-thought" prompting in the system message to prevent the AI from giving away answers immediately.
Solution:
Instruct the model to:
Instruct the model to:
"Work through the problem step-by-step before providing the final answer. Do not reveal the final answer until the student has attempted the steps."Task 2
Apply an "out" to prevent fabrications (hallucinations) when the AI doesn't know the answer.
Solution:
Add the explicit instruction:
Add the explicit instruction:
"If you do not know the answer based on the provided text or standard curriculum, state clearly that you do not know."